import { Module, NestModule, MiddlewareConsumer, RequestMethod } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { SysModules } from './sysModules'
import { Modules } from './modules';
import { JwtMiddlewares } from './middlewares/jwtMiddlewares'
import { FactoryMiddlewares } from './middlewares/factoryMiddlewares'

@Module({
  imports: [
    SysModules,
    Modules,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer
      .apply(JwtMiddlewares).exclude(
        { path: 'auth/{*splat}', method: RequestMethod.ALL },
        { path: 'admin/tenant/{*splat}', method: RequestMethod.ALL },
        { path: 'admin/sysTenantConfig/{*splat}', method: RequestMethod.ALL },
        { path: 'admin/param/{*splat}', method: RequestMethod.ALL },
        { path: 'oss/{*splat}', method: RequestMethod.GET },
      ).forRoutes('*')
      .apply(FactoryMiddlewares).forRoutes('*')
  }
}
